package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Qqcards;
import com.ruoyi.system.service.IQqcardsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * qq卡 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-05-28
 */
@Controller
@RequestMapping("/system/qqcards")
public class QqcardsController extends BaseController
{
    private String prefix = "system/qqcards";
	
	@Autowired
	private IQqcardsService qqcardsService;
	
	@RequiresPermissions("system:qqcards:view")
	@GetMapping()
	public String qqcards()
	{
	    return prefix + "/qqcards";
	}
	
	/**
	 * 查询qq卡列表
	 */
	@RequiresPermissions("system:qqcards:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Qqcards qqcards)
	{
		startPage();
        List<Qqcards> list = qqcardsService.selectQqcardsList(qqcards);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出qq卡列表
	 */
	@RequiresPermissions("system:qqcards:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Qqcards qqcards)
    {
    	List<Qqcards> list = qqcardsService.selectQqcardsList(qqcards);
        ExcelUtil<Qqcards> util = new ExcelUtil<Qqcards>(Qqcards.class);
        return util.exportExcel(list, "qqcards");
    }
	
	/**
	 * 新增qq卡
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存qq卡
	 */
	@RequiresPermissions("system:qqcards:add")
	@Log(title = "qq卡", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Qqcards qqcards)
	{		
		return toAjax(qqcardsService.insertQqcards(qqcards));
	}

	/**
	 * 修改qq卡
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Qqcards qqcards = qqcardsService.selectQqcardsById(id);
		mmap.put("qqcards", qqcards);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存qq卡
	 */
	@RequiresPermissions("system:qqcards:edit")
	@Log(title = "qq卡", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Qqcards qqcards)
	{		
		return toAjax(qqcardsService.updateQqcards(qqcards));
	}
	
	/**
	 * 删除qq卡
	 */
	@RequiresPermissions("system:qqcards:remove")
	@Log(title = "qq卡", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(qqcardsService.deleteQqcardsByIds(ids));
	}
	
}
